package com.zhisheng.web17.demos.web;

import com.github.pagehelper.PageInfo;
import com.zhisheng.web17.demos.pojo.User;
import com.zhisheng.web17.demos.resp.MyResponseResult;
import com.zhisheng.web17.demos.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 创建者： 智晟全哥
 */

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    // 增 删 改  查(分页查列表,根据id查对象)
    @PostMapping
    public MyResponseResult<Integer> insertUser(@RequestBody User user){
        return userService.insertUser2(user);
    }

    @GetMapping
    public MyResponseResult<PageInfo<User>> listUserByPage(@RequestParam(defaultValue = "1")Integer pageNum, @RequestParam(defaultValue = "2")Integer pageSize){
        return userService.listUserByPage(pageNum,pageSize);
    }

    @DeleteMapping("/{id}")
    public MyResponseResult<Integer> delById(@PathVariable("id") Integer id){
        return userService.delById(id);
    }

}
